package com.bmf.module.rbac.controller;

import com.bmf.module.rbac.service.OrganizationService;
import com.bmf.module.rbac.vo.OrganizationCreateVo;
import com.bmf.module.rbac.vo.OrganizationResultVo;
import com.bmf.module.rbac.vo.OrganizationUpdateVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.io.Serializable;
import java.util.List;
import com.bmf.core.result.R;

/**
 * (Organization)表控制层
 *
 * @author makejava
 * @since 2023-01-06 17:01:18
 */
@RestController
@RequestMapping("organization")
@Api(tags = {"组织接口"})
public class OrganizationController{
    /**
     * 服务对象
     */
    @Autowired
    private OrganizationService organizationService;

    /**
     * 查询所有数据
     *
     * @return 所有数据
     */
    @GetMapping
    @ApiOperation(value = "查询")
    public R<List<OrganizationResultVo>> selectAll() {
        return R.success(organizationService.selectAll());
    }

    /**
     * 查询组织或组织下人员
     *
     * @return 所有数据
     */
    @GetMapping("/selectByOrganizationId")
    @ApiOperation(value = "查询组织或组织下人员")
    public R<List<OrganizationResultVo>> selectByOrganizationId(@RequestParam(required = false) Integer id) {
        return R.success(organizationService.selectByOrganizationId(id));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    @ApiOperation(value = "根据id查询")
    public R selectOne(@PathVariable Serializable id) {
        return R.success(organizationService.selectOne(id));
    }

    /**
     * 新增数据
     *
     * @param organizationCreateVo 实体对象
     * @return 新增结果
     */
    @PostMapping
    @ApiOperation(value = "添加")
    public R<Integer> insert(@RequestBody OrganizationCreateVo organizationCreateVo) {
        return R.success(organizationService.insert(organizationCreateVo));
    }

    /**
     * 修改数据
     *
     * @param organizationUpdateVo 实体对象
     * @return 修改结果
     */
    @PutMapping
    @ApiOperation(value = "修改")
    public R<Void> update(@RequestBody OrganizationUpdateVo organizationUpdateVo) {
        organizationService.update(organizationUpdateVo);
        return R.ok();
    }

    /**
     * 删除数据
     *
     * @param ids 主键结合
     * @return 删除结果
     */
    @DeleteMapping
    @ApiOperation(value = "删除")
    public R<Void> delete(@RequestBody List<Integer> ids) {
        organizationService.delete(ids);
        return R.ok();
    }
}

